/* Copyright (c) 2021, National University of Defense Technology. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PARBSR_MATRIX_H
#define PARBSR_MATRIX_H

#include "par_operator.h"
#include "bsr_matrix.h"

namespace YHAMG
{

struct ParBSR_Matrix : public Par_Operator
{
	BSR_Matrix LocLoc;
	BSR_Matrix LocExt;

	int num_neighbors;
	int* neighbor_ranks;

	int* Ext_ptr;
	int* Ext_map;

	int* send_ptr;
	int* send_list;
	double* send_buffer;
	
	Vector x_Ext;

	ParBSR_Matrix();
	ParBSR_Matrix(MPI_Comm comm, int LocLoc_rows, int LocLoc_cols, int LocExt_cols, int block_size, 
	int* LocLoc_rowptr, int* LocLoc_colind, double* LocLoc_values, int LocLoc_ref, 
	int* LocExt_rowptr, int* LocExt_colind, double* LocExt_values, int LocExt_ref,
	int num_neighbors, int* neighbor_ranks, int* Ext_ptr, int* Ext_map);
	ParBSR_Matrix(const ParBSR_Matrix& A);
	ParBSR_Matrix(ParBSR_Matrix&& A);
	~ParBSR_Matrix();
	ParBSR_Matrix& operator=(const ParBSR_Matrix& A);
	ParBSR_Matrix& operator=(ParBSR_Matrix&& A);
	
	void Free();
	void Reference(const ParBSR_Matrix& A);
	void ExchangeHalo(const Vector& x_Loc, const Vector& x_Ext) const;
	void SetupHalo();
	int InSize() const;
	int OutSize() const;
	void Apply(const Par_Vector& x, const Par_Vector& y) const;
};

}

#endif